#!/bin/bash


# 检查启动目录
bash excdirs.sh

# 启动celery beat
# celery -A iClouds beat &

# 启动celery worker
# celery multi start w1 -A iClouds -l info --logfile=/opt/logs/%n%I.log


cd /opt/iClouds

# 初始化
python3 manage.py inited


nohup celery -A iClouds worker -l info --logfile=/opt/logs/celery_worker.log &
nohup celery -A iClouds beat -l info --logfile=/opt/logs/celery_beat.log &
# --scheduler django_celery_beat.schedulers:DatabaseScheduler

# 用于开发环境的项目单线程启动
python3 manage.py runserver 0.0.0.0:8000

# 异步关闭 立即返回
# celery multi stop w1

# 异步关闭 立即返回
PROCESS=`ps -ef|grep celery|grep -v grep|grep -v PPID|awk '{ print $2}'`
for i in $PROCESS
do
    echo "Kill the $1 process [ $i ]"
    kill -9 $i
done